package com.hgl.listener;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextAttributeEvent;
import javax.servlet.ServletContextAttributeListener;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.ServletRequestAttributeEvent;
import javax.servlet.ServletRequestAttributeListener;
import javax.servlet.ServletRequestEvent;
import javax.servlet.ServletRequestListener;
import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionAttributeListener;
import javax.servlet.http.HttpSessionBindingEvent;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@WebListener
public class Listener01 implements ServletContextListener,HttpSessionListener,ServletRequestListener,ServletContextAttributeListener,HttpSessionAttributeListener,ServletRequestAttributeListener{
	private static Logger log=LoggerFactory.getLogger(Listener01.class);
	@Override
	public void contextInitialized(ServletContextEvent sce) {
		// 上下文创建后调用
		// 工程初始化和全局的设置
		ServletContext application = sce.getServletContext();
		log.debug("工程的上下文对象创建了"+application);
		application.setAttribute("webName", "XXXX信息网");
	}
	
	@Override
	public void contextDestroyed(ServletContextEvent sce) {
		// 上下文销毁前调用
		// 工程全局的销毁和保存工作
		ServletContext application = sce.getServletContext();
		log.debug("工程的上下文对象销毁了"+application);
	}
	
	@Override
	public void sessionCreated(HttpSessionEvent se) {
		//会话创建
		HttpSession session =se.getSession();
	}
	
	@Override
	public void sessionDestroyed(HttpSessionEvent se) {
		//会话销毁
		HttpSession session =se.getSession();
	}
	
	@Override
	public void requestInitialized(ServletRequestEvent sre) {
		// 请求的创建
		HttpServletRequest request = (HttpServletRequest)sre.getServletRequest();
	}
	
	@Override
	public void requestDestroyed(ServletRequestEvent sre) {
		// 请求的销毁
		HttpServletRequest request = (HttpServletRequest)sre.getServletRequest();
	}
	
	@Override
	public void attributeAdded(ServletContextAttributeEvent event) {
		// 上下文属性添加
		ServletContext application = event.getServletContext();
		String name = event.getName();//添加的属性名
		Object value = event.getValue();//添加的属性值
	}
	
	@Override
	public void attributeRemoved(ServletContextAttributeEvent event) {
		// 上下文属性移除
	}
	
	@Override
	public void attributeReplaced(ServletContextAttributeEvent event) {
		// 上下文属性的替换
	}

	@Override
	public void attributeAdded(ServletRequestAttributeEvent srae) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void attributeRemoved(ServletRequestAttributeEvent srae) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void attributeReplaced(ServletRequestAttributeEvent srae) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void attributeAdded(HttpSessionBindingEvent event) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void attributeRemoved(HttpSessionBindingEvent event) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void attributeReplaced(HttpSessionBindingEvent event) {
		// TODO Auto-generated method stub
		
	}

	

}
